// https://www.acwing.com/problem/content/869/

#include <cstdio>
using namespace std;

int main() {
    int n, x;
    scanf("%d", &n);
    if ()

    for (int i=0; i<n; i++) {
        scanf("%d", &x);
        for (int t=2; t <= x / t; t++) {
            if (x % t == 0) {
                int cnt = 0;
                while (x % t == 0) {
                    x /= t;
                    cnt++;
                }
                printf("%d %d\n", t, cnt);
            }
        }
        if (x > 1) {
            printf("%d 1\n", x);
        }
        printf("\n");
    }
    return 0;
}
